<template>
	<div class="detail_main clearfix">
		<div class="detail_others">
			<div class="detail_other hover_active" @click="checkCollect(true)" v-if='!collect'>
				<img src="@/images/case_itemP81.png" class="active" />
				<img src="@/images/case_itemP82.png" class="normal" />
				<div class="detail_isselectP">收藏</div>
			</div>
			<div class="detail_other hover_active" @click="checkCollect(false)" v-if='collect'>
				<img src="@/images/case_itemP81.png" class="normal" />
				<img src="@/images/case_itemP82.png" class="active" />
				<div class="detail_isselectP">取消收藏</div>
			</div>
			<div class="detail_other close" @click="closeItem">
				<img src="@/images/case_item_close.png" class="normal" />
				<div class="detail_isselectP">关闭</div>
			</div>
		</div>
		<dcmviewmain :stuuid='stuuid' :isSimplify='true'></dcmviewmain>
	</div>
</template>

<script>
	import { viewImg, collectStatus, collectImg } from '@/api/image.js'
	import dcmviewmain from '@/components/dcmviewmain.vue'
	export default {
		components: {
			dcmviewmain
		},
		data() {
			return {
				dcmId: this.$route.query.dcmId,
				stuuid: this.$route.query.stuuid,
				collect: false,
			}
		},
		created() {
			this.setView()
			this.getSelectState()
		},
		mounted() {

		},
		methods: {
			closeItem(){
				window.close()
			},
			getSelectState() {
				collectStatus({
					dcmId: this.dcmId,
				}).then(res => {
					this.collect = res.data || false
				})
			},
			checkCollect(collect) {
				var message = collect ? '确定收藏此影像?' : '确定取消收藏此影像?'
				this.$confirm(message, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(() => {
					collectImg({
						dcmId: this.dcmId,
						collect
					}).then(res => {
						if(res.code == 200) {
							this.getSelectState()
						} else {
							this.$message({
								type: 'error',
								message: res.message
							})
						}
					})
				}).catch(() => {})

			},
			setView() {
				viewImg({
					dcmId: this.dcmId
				})
			},
		},
	}
</script>